package 动态数组.栈.栈的括号匹配;

import 动态数组.栈.ArrayStack;

/**
 * 使用栈来完成括号的匹配问题
 */
public class MatchBracket {
    public static void main(String[] args) {
        String str = "{<>[]()><}";
        ArrayStack<Character> stack = new ArrayStack<>();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (stack.isEmpty()){
                stack.push(c);
            }else {
                Character top = stack.peek();
                if (top - c == -1 || top - c == -2){
                    stack.pop();
                }else {
                    stack.push(c);
                }
            }
        }
        System.out.println(stack.isEmpty());
        System.out.println(stack);
    }
}
